/**
 * @author jmikhail
 *
 */
package unitTests;

import mainClasses.*;
import pieces.*;
import junit.framework.TestCase;


public class RookTest extends TestCase {

	Board testingBoard = new Board();
	/**
	 * @param name - Test name
	 */
	public RookTest(String name) {
		super(name);
	}

	/**
	 * Test method for {@link pieces.Rook#Rook(int, int, mainClasses.Board, java.lang.String)}.
	 */
	public void testRook() {
		Rook testingRook8 = new Rook(2,5, testingBoard, "White");
		assertEquals(testingRook8.getX(), 2);
		assertEquals(testingRook8.getY(), 5);
		assertTrue(testingRook8.board.equals(testingBoard));
		assertFalse(testingRook8.getClass().equals(NullPiece.class));
		assertEquals(testingRook8.getType(), "  Rook   ");
		assertEquals(testingRook8.getSide(), "White");
		
	}

	
	
	/*
	 * @see junit.framework.TestCase#setUp()
	 */
	protected void setUp() throws Exception {
		super.setUp();
	}

	
	
	/*
	 * @see junit.framework.TestCase#tearDown()
	 */
	protected void tearDown() throws Exception {
		super.tearDown();
	}

	
	
	/**
	 * Test method for {@link pieces.Rook#movePossible(java.awt.Point)}.
	 */
	public void testMovePossible() {
		Rook WhiteTestingRook1 = new Rook(1, 1, testingBoard, "White");
		Rook WhiteTestingRook2 = new Rook(1, 6, testingBoard, "White");

		Rook BlackTestingRook1 = new Rook(6, 1, testingBoard, "Black");
		Rook BlackTestingRook2 = new Rook(6, 6, testingBoard, "Black");

		testingBoard.add(WhiteTestingRook1);
		testingBoard.add(WhiteTestingRook2);

		testingBoard.add(BlackTestingRook1);
		testingBoard.add(BlackTestingRook2);	//Add all the rooks to the board
		
		/*
		 * Testing for the movement of a white rook
		 */
		assertTrue(WhiteTestingRook1.movePossible(1,2));	//Upward Movement into an empty block
		assertTrue(WhiteTestingRook1.movePossible(0,1));	//Left Movement into an empty block
		assertTrue(WhiteTestingRook1.movePossible(1,0));	//Downward Movement into an empty block
		assertTrue(WhiteTestingRook1.movePossible(2,1));	//Right Movement into an empty block
		assertFalse(WhiteTestingRook1.movePossible(0,2));//Diagonal Movement into an empty block
		assertFalse(WhiteTestingRook1.movePossible(0,0));//Diagonal Movement into an empty block
		assertFalse(WhiteTestingRook1.movePossible(2,0));//Diagonal Movement into an empty block
		assertFalse(WhiteTestingRook1.movePossible(2,2));//Diagonal Movement into an empty block
		
		assertTrue(WhiteTestingRook1.movePossible(6,1));	//Checks that a white rook can kill a black piece
		assertFalse(WhiteTestingRook1.movePossible(1,6));//Checks that a white rook can't kill a white piece
		
		assertFalse(WhiteTestingRook1.movePossible(1,7));//Checks that a white rook can't jump over a white piece
		assertFalse(WhiteTestingRook1.movePossible(7,1));//Checks that a white rook can't jump over a black piece
		
		
		/*
		 * Testing for the movement of a black rook
		 */
		assertTrue(BlackTestingRook2.movePossible(6,7));	//Upward Movement into an empty block
		assertTrue(BlackTestingRook2.movePossible(5,6));	//Left Movement into an empty block
		assertTrue(BlackTestingRook2.movePossible(6,5));	//Downward Movement into an empty block
		assertTrue(BlackTestingRook2.movePossible(7,6));	//Right Movement into an empty block
		assertFalse(BlackTestingRook2.movePossible(5,7));//Diagonal Movement into an empty block
		assertFalse(BlackTestingRook2.movePossible(7,7));//Diagonal Movement into an empty block
		assertFalse(BlackTestingRook2.movePossible(5,5));//Diagonal Movement into an empty block
		assertFalse(BlackTestingRook2.movePossible(7,5));//Diagonal Movement into an empty block
		
		assertTrue(BlackTestingRook2.movePossible(1,6));	//Checks that a black rook can kill a white piece
		assertFalse(BlackTestingRook2.movePossible(6,1));//Checks that a black rook can't kill a black piece
		
		assertFalse(BlackTestingRook2.movePossible(0,6));//Checks that a black rook can't jump over a white piece
		assertFalse(BlackTestingRook2.movePossible(6,0));//Checks that a black rook can't jump over a black piece
	}


	

	/**
	 * Test method for {@link pieces.Piece#isEnemy(java.awt.Point)}.
	 */
	public void testIsEnemy() {
		Rook WhiteTestingRook1 = new Rook(1, 1, testingBoard, "White");
		Rook WhiteTestingRook2 = new Rook(2, 2, testingBoard, "White");
		Rook BlackTestingRook1 = new Rook(3, 3, testingBoard, "Black");
		Rook BlackTestingRook2 = new Rook(4, 4, testingBoard, "Black");
		
		testingBoard.add(WhiteTestingRook1);
		testingBoard.add(WhiteTestingRook2);
		testingBoard.add(BlackTestingRook1);
		testingBoard.add(BlackTestingRook2);
		
		assertTrue(WhiteTestingRook1.isEnemy(3,3));	//Checks that BlackTestingRook1 IS an enemy
		assertFalse(WhiteTestingRook1.isEnemy(2,2));	//Checks that WhiteTestingRook2 IS NOT an enemy
		assertFalse(WhiteTestingRook1.isEnemy(7,7));	//Checks that a NullPiece IS NOT an enemy
		
		assertTrue(BlackTestingRook1.isEnemy(2,2));	//Checks that WhiteTestingRook2 IS an enemy
		assertFalse(BlackTestingRook1.isEnemy(4,4));	//Checks that BlackTestingRook2 IS NOT an enemy
		assertFalse(BlackTestingRook1.isEnemy(7,7));	//Checks that a NullPiece IS NOT an enemy
	}



	

	/**
	 * Test method for {@link pieces.Piece#getPoint()}.
	 */
	public void testGetPoint() {
		
		Rook testingRook5 = new Rook(3, 3, testingBoard, "White");
		assertTrue(testingRook5.getX()==3 && testingRook5.getY()==3);
		assertFalse(testingRook5.getX()==4 || testingRook5.getY()==5);
		
		Rook testingRook6 = new Rook(4, 5, testingBoard, "White");
		assertTrue(testingRook6.getX()==4 && testingRook6.getY()==5);
		assertFalse(testingRook6.getX()==3 || testingRook6.getY()==3);
	}

	
	
	
	
	
	/**
	 * Test method for {@link pieces.Piece#getType()}.
	 */
	public void testGetType() {
		Rook testingRook4 = new Rook(5, 5, testingBoard, "White");
		
		assertEquals(testingRook4.getType(), "  Rook   ");

		testingRook4.setType("RandomType");
		assertEquals(testingRook4.getType(), "RandomType");
	}

	
	
	/**
	 * Test method for {@link pieces.Piece#getSide()}.
	 */
	public void testGetSide() {
		Rook testingRook3 = new Rook(6, 6, testingBoard, "White");

		assertEquals(testingRook3.getSide(), "White");
	
	}

	
	
	
	/**
	 * Test method for {@link pieces.Piece#setType(java.lang.String)}.
	 */
	public void testSetType() {
		Rook testingRook2 = new Rook(5, 5, testingBoard, "White");

		testingRook2.setType("RandomType");
		assertEquals(testingRook2.getType(), "RandomType");
	}

	
	
	
	
	/**
	 * Test method for {@link pieces.Piece#isEqual(pieces.Piece)}.
	 */
	public void testIsEqual() {
		Rook testingRook9 = new Rook(4, 1, testingBoard, "White");
		Rook testingRook10 = new Rook(4, 1, testingBoard, "White");
		Rook testingRook11 = new Rook(3, 1, testingBoard, "White");

		
		assertTrue(testingRook9.isEqual(testingRook10));
		assertFalse(testingRook9.isEqual(testingRook11));
	}

	
	
	
	/**
	 * Test method for {@link pieces.Piece#changePosition(java.awt.Point)}.
	 */
	public void testChangePosition() {
		Rook testingRook1 = new Rook(3, 7, testingBoard, "White");
		testingRook1.changePosition(3,2);
		assertEquals(testingRook1.getX(), 3);
		assertEquals(testingRook1.getY(), 2);
		
		testingRook1.changePosition(7,2);
		assertEquals(testingRook1.getX(), 7);
		assertEquals(testingRook1.getY(), 2);
	}

}
